using UnityEngine;

public class UIF_Player_Script : MonoBehaviour
{
    [Header("移动速度")]
    public float moveSpeed = 50f;
    [Header("转身速度")]
    public float rotateSpeed = 168f;
    
    private float hor, ver;
    private Transform health;
    private Vector3 healthDirection;

    private void Awake()
    {
        healthDirection = transform.forward;
        health = GameObject.Find("Health").transform;
    }

    void Update()
    {
        // 玩家移动和转身
        hor = Input.GetAxis("Horizontal");
        ver = Input.GetAxis("Vertical");
        transform.position += transform.forward * ver * Time.deltaTime * moveSpeed;
        transform.eulerAngles += Vector3.up * hor * Time.deltaTime * rotateSpeed;
        // 血条朝向重置为初始朝向, 绕y轴旋转
        // Quaternion targetRotation = Quaternion.LookRotation(healthDirection);
        // health.rotation = Quaternion.Lerp(health.rotation, targetRotation, 0.8f);
        // 硬转向
        health.rotation = Quaternion.LookRotation(healthDirection, Vector3.up);
    }
}
